package com.cyou.gamehistory.exception;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import com.cyou.framework.exception.ExceptionUtility;

/***
 * 异常处理器  （加入打印日志）
 * 将异常统一由spring异常处理
 * @author wangzhang
 *
 */
public class MyExceptionHandler implements HandlerExceptionResolver  {
	private static final Logger logger = LoggerFactory.getLogger(MyExceptionHandler.class);
	@Override
	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception e) {
		logger.error("Catch exception",e);
		Map<String,Object> map = new HashMap<String,Object>();  
        map.put("errorMsg", ExceptionUtility.getStackTraceAsString(e));//将错误信息传递给view  
		return new ModelAndView("error/500",map);  
	}

	

}
